
#include <gtest/gtest.h>

#include "DBManager/IService/Result/Random/ICROSS_PSDService.h"

#include "../../TestDB.h"
using namespace SG::DataStructure::FEM;
using namespace SG::DataStructure::Post;
using namespace SG::DBManager;

TEST (O_RANDOM, CROSS_PSDService)
{
    DB::ServiceFactory->ClearDatabase ();
    // 获取仓库服务
    auto service = DB::ServiceFactory->get<ICROSS_PSDService> ();

    int randomSid = 999;

    // 创建存储的数据，添加数据
    std::vector<CROSS_PSDData> saveData;

    CROSS_PSDData data;

    for (size_t i = 0; i < 10; i++)
    {
        data.m_RCROSS   = i;
        data.m_domainId = 1;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ randomSid, 0.1, SG::DBManager::Post::DomainRequest::RandomResultType::PSDS }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);  // adds内部会清空saveData数据

    saveData.clear ();
    // 创建存储的数据，添加数据
    for (size_t i = 0; i < 10; i++)
    {
        data.m_RCROSS   = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ randomSid, 0.2, SG::DBManager::Post::DomainRequest::RandomResultType::PSDS }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);

    saveData.clear ();
    // 创建判断的数据
    for (size_t i = 0; i < 10; i++)
    {
        data.m_RCROSS   = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }

    // 通过DomainId获取数据，测试接口正确性
    std::vector<CROSS_PSDData> result;
    ASSERT_TRUE (service->Find (2, result) == SG::DataStructure::Common::Status::STATUS_Success);
}
